package com.ffiams;

import com.github.fppt.jedismock.RedisServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import java.io.IOException;

/**
 * 启动程序
 *
 * @author
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class FfiamsApplication {
    private static RedisServer redisServer;
    private static boolean redisStarted = false;

    public static void main(String[] args) {
        // System.setProperty("spring.devtools.restart.enabled", "false");
        if (!redisStarted) {
            try {
                redisServer = new RedisServer(6379); // 尝试使用 6379 端口
                redisServer.start();
                redisStarted = true;
            } catch (IOException e) {
                // 如果 6379 端口被占用，尝试其他端口
                try {
                    redisServer = new RedisServer(6380); // 使用 6380 端口
                    redisServer.start();
                    redisStarted = true;
                } catch (IOException ex) {
                    throw new RuntimeException("Failed to start RedisServer on ports 6379 and 6380", ex);
                }
            }
        }
        SpringApplication.run(FfiamsApplication.class, args);
        System.out.println("admin 启动成功");
    }
}